// 英文字符匹配：大小写不敏感  's 等同 is 're 等同 are 'm 等同 am  've 等同 have
// gonna = going to   wanna = want to gotta = have got to
export const compareSentence = function (val1, val2) {
  val1 = val1.replace(/'s/g, ' is')
  val1 = val1.replace(/'re/g, ' are')
  val1 = val1.replace(/'m/g, ' am')
  val2 = val2.replace(/'s/g, ' is')
  val2 = val2.replace(/'re/g, ' are')
  val2 = val2.replace(/'m/g, ' am')
  val1 = val1.toLowerCase()
  val2 = val2.toLowerCase()
  return val1 === val2
}

// 获取浏览器缓存的当前台词进度数据
export const getLocalData = function () {
  let localData = localStorage.getItem('sentenceProgress')
  if (localData) {
    localData = JSON.parse(localData)
  } else {
    localData = {}
  }
  return localData
}
export const setLocalData = function (data = {}) {
  let localData = getLocalData()
  localData = {
    ...localData,
    ...data
  }
  localStorage.setItem('sentenceProgress', JSON.stringify(localData))
}

// 获取浏览器缓存得当前单词练习进度
export const getLocalWordData = function () {
  let localData = localStorage.getItem('wordProgress')
  if (localData) {
    localData = JSON.parse(localData)
  } else {
    localData = {}
  }
  return localData
}
export const setLocalWordData = function (data = {}) {
  let localData = getLocalWordData()
  localData = {
    ...localData,
    ...data
  }
  localStorage.setItem('wordProgress', JSON.stringify(localData))
}

// 进度初始化
export const getProgress = function (completeNum, totalNum, defaultValue = 0) {
  if (totalNum === 0) {
    return defaultValue
  } else {
    return parseInt((completeNum / totalNum).toFixed(2) * 100 + 0.1)
  }
}
